package com.hutao.manage.util;

import java.math.BigDecimal;
import java.util.List;

public class ObjectUtil {

	/**
	 * 获取字符串对象
	 * @param obj
	 * @return
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static String getStringValue(Object obj){
		if(obj instanceof String){
			return (String)obj;
		}else if(obj instanceof List){
			return String.join(";", (List)obj);
		}else{
			return null;
		}
	}
	
	/**
	 * 获取Integer对象
	 * @param obj
	 * @return
	 */
	public static Integer getIntegerValue(Object obj){
		if(obj == null){
			return null;
		}else if(obj instanceof Integer){
			return (Integer)obj;
		}else if(obj instanceof Long){
			return ((Long)obj).intValue();
		}else if(obj instanceof Float){
			if(Float.isNaN((Float)obj)){
				return 0;
			}
			return ((Float)obj).intValue();
		}else if(obj instanceof Double){
			if(Double.isNaN((Double)obj)){
				return 0;
			}
			return ((Double)obj).intValue();
		}else if(obj instanceof BigDecimal){
			return ((BigDecimal)obj).intValue();
		}else if(obj instanceof String){
			return new Integer((String)obj);
		}else{
			return null;
		}
	}
}
